{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import scipy.stats\n",
    "import seaborn\n",
    "import ergo"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Testing the internal method used to build a CDF from a bag of samples:\n",
    "\n",
    "Generate some samples, and convert to Foretold CDF:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "loc = 50\n",
    "scale = 5\n",
    "samples = np.random.normal(loc, scale, size=2000)\n",
    "cdf = ergo.foretold.ForetoldCdf.from_samples(samples, length=10)\n",
    "cdf"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Compare the CDF derived from samples with the true CDF:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "xs = np.linspace(loc - scale * 4, loc + scale * 4, 100)\n",
    "ys = scipy.stats.norm.cdf(xs, loc=loc, scale=scale)\n",
    "seaborn.lineplot(xs, ys);\n",
    "seaborn.lineplot(cdf.xs, cdf.ys);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Testing submission:\n",
    "\n",
    "Submit samples as a prediction (measurement) of a [question](https://www.foretold.io/c/f45577e4-f1b0-4bba-8cf6-63944e63d70c/m/cf86da3f-c257-4787-b526-3ef3cb670cb4) outcome (measureable):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "token = \"YOUR-TOKEN\"\n",
    "foretold = ergo.Foretold(token)\n",
    "question = foretold.get_question(\"cf86da3f-c257-4787-b526-3ef3cb670cb4\")\n",
    "response = question.submit_from_samples(samples, length=20)\n",
    "response"
   ]
  }
 ],
 "metadata": {
  "jupytext": {
   "cell_metadata_filter": "-all",
   "main_language": "python",
   "notebook_metadata_filter": "-all"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
